#!/bin/bash

set -e

function usage() {
    echo "Usage: $( basename $0 ) [-r <reviewer> | -h]"
    echo "      用纯git方法push caffe量化工具到gerrit"
    echo "      命令行参数" 
    echo "      -r <reviewer> 可以有多个" 
    echo "      -h 输出本信息"
    exit 1
}   

repo="origin"
branch="master"
# 缺省的reviewer
reviewer="yangchongxu"

while getopts "r:h" arg
do
    case $arg in
        r)
            reviewer="${reviewer},$OPTARG"
            ;;
        *)
            usage
            ;;
    esac
done

if [ -z "${reviewer}" ]
then
    usage
fi

# 先与服务器同步
echo git pull --rebase ${repo} "${branch}"
git pull --rebase ${repo} "${branch}"
# Gerrit在 refs/for/<branch_name> 分支上追踪审核<branch_name>分支的更改
# %r 指定Reviewer
echo git push ${repo} "HEAD:refs/for/${branch}%r=${reviewer}"
git push ${repo} "HEAD:refs/for/${branch}%r=${reviewer}"
